#region using statements

using DPSF;

using Microsoft.Xna.Framework;

using NGen.Managers;
using NGen.Managers.Logging;

#endregion

namespace NGen.Experimental.DPSF
{
	public class ManagerParticles : GameManager, IManagerParticles
	{
		#region local fields

		///<summary>
		///	DPSF particle system manager object
		///</summary>
		private readonly ParticleSystemManager m_particleManager;

		#endregion

		#region constructors

		public ManagerParticles() {
			m_particleManager = new ParticleSystemManager();
			CurrentLoggingLevel = LoggingLevel.MINIMAL;
			Logger = GameEngine.GetService<IManagerLogs>().Log<ManagerParticles>();
			SkipUpdate = false;
			SkipDraw = false;
			UpdateOrder = 0;
			DrawOrder = 300;
		}

		#endregion

		#region IGameManager implementation

		/// <summary>
		/// 	get or set if this manager should skip its Update call
		/// </summary>
		public new bool SkipUpdate {
			get { return !m_particleManager.Enabled; }
			set { m_particleManager.Enabled = !value; }
		}

		/// <summary>
		/// 	get or set if this manager should skip its Draw call
		/// </summary>
		public new bool SkipDraw {
			get { return !m_particleManager.Visible; }
			set { m_particleManager.Visible = !value; }
		}

		/// <summary>
		/// 	update this manager
		/// </summary>
		/// <param name = "p_gameTime">snapshot of timing values</param>
		internal override void Update(GameTime p_gameTime) {
			m_particleManager.UpdateAllParticleSystemsForced((float) p_gameTime.ElapsedGameTime.TotalSeconds);
		}

		/// <summary>
		/// 	draw this manager
		/// </summary>
		/// <param name = "p_gameTime">snapshot of timing values</param>
		internal override void Draw(GameTime p_gameTime) {
			m_particleManager.DrawAllParticleSystemsForced();
		}

		/// <summary>
		/// 	cleanup this manager
		/// </summary>
		internal override void Cleanup() {
			m_particleManager.DestroyAndRemoveAllParticleSystems();
		}

		#endregion

		#region IManagerParticles implementation

		/// <summary>
		/// 	get or set the default number of particles to initially allocate memory for, per system
		/// </summary>
		public int DefaultInitialParticleAllocationCountPerSystem { get; set; }

		/// <summary>
		/// 	get or set the default maximum number of particles per system
		/// </summary>
		public int DefaultMaximumParticlesPerSystem { get; set; }

		public void AddParticleSystem(IDPSFParticleSystem p_system) {
			m_particleManager.AddParticleSystem(p_system);
			p_system.AutoInitialize(GameEngine.GraphicsDevice, GameEngine.GameContent, GameEngine.SpriteBatch);
		}

		public void RemoveParticleSystem(IDPSFParticleSystem p_system) {
			m_particleManager.RemoveParticleSystem(p_system);
			p_system.Destroy();
		}

		/// <summary>
		/// 	Returns the DPSF particle system manager object
		/// </summary>
		/// <returns></returns>
		public ParticleSystemManager GetInternalParticleManager() {
			return m_particleManager;
		}

		#endregion
	}
}